import { Controller, Get, Res, Post, Body, Patch, Param, Delete, UseInterceptors, UploadedFile } from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor,FilesInterceptor} from '@nestjs/platform-express'
import { join } from 'path';
import { Response } from 'express';
import { zip } from 'compressing'

@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post('album')
  @UseInterceptors(FileInterceptor('file'))
  upload(@UploadedFile() file){
    console.log(file,"file");
    return "骚货骚货！！！";
  }
  @Get('export') //直接下载
  downLoad(@Res() res:Response){
    const url = join(__dirname,'../images/1712020167926.jpg');
    res.download(url);
  }
  @Get('stream') //文件流下载
  async down(@Res() res:Response){
    const url = join(__dirname,'../images/1712043290688.jpg');
    const tarStream = new zip.Stream();
    await tarStream.addEntry(url);
    res.setHeader('Content-Type', 'application/octet-stream');
    res.setHeader(
      'Content-Disposition',  
      `attachment; filename=zhengou`,
    );

    tarStream.pipe(res);

  }
}
